<?php

namespace App;

/**
 * 对象注册器,参考Zend_Registry,实现php5.3+的新特性，可调用结构
 */
final class Registry extends ArrayObject implements Callable
{
    public static $map = array();

    protected static $_instance = NULL;

    public static function getInstance()
    {
        if (self::$_instance !== NULL)
            self::$_instance = new self();
        return self::$_instance;
    }

    public function __invoke($name, $value = NULL)
    {
        $self = self::getInstance();
        if (is_null($value)) {
            return $self->offsetGet($name);
        } else {
            $self->offsetSet($name, $value);
            return $self;
        }
    }

}